package utopia_activities;

import java.util.Collection;
import java.util.Date;
import java.util.Locale;
import java.util.UUID;

import org.apache.http.impl.client.DefaultHttpClient;
import org.simpleframework.xml.core.Persister;
import org.simpleframework.xml.transform.RegistryMatcher;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;

import com.example.utopia.shoppinglist.R;

import de.dhbw_stuttgart.wi2011i.outofapples.DateTransform;
import de.dhbw_stuttgart.wi2011i.outofapples.UUIDTransform;
import de.dhbw_stuttgart.wi2011i.outofapples.dtos.ShoppingList;
import de.dhbw_stuttgart.wi2011i.outofapples.logging.LoggerImpl;
import de.dhbw_stuttgart.wi2011i.outofapples.persistence.OnlineEinkaufsblock;

public class Utopia extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {        
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_utopia);

        final Context context = this;
        
        /*AsyncTask<Void, Void, Collection<ShoppingList>> task = new AsyncTask<Void, Void, Collection<ShoppingList>>() {
			@Override
			protected Collection<ShoppingList> doInBackground(Void... params) {
				RegistryMatcher matcher = new RegistryMatcher();
		        
		        matcher.bind(UUID.class, new UUIDTransform());
		        matcher.bind(Date.class, new DateTransform(java.text.DateFormat.getDateInstance(java.text.DateFormat.DEFAULT, Locale.US)));
		        
		        Persister persister = new Persister(matcher);
		        OnlineEinkaufsblock block = new OnlineEinkaufsblock(new LoggerImpl(), persister, context, new DefaultHttpClient());
		        block.setUrl("http://www.matthiaswelz.de:8094/OutOfAPPles");
		        
		        block.tryLogin("Test", "1234567");
				Log.d("OutOfAPPles", "Logged in");
				
				//Eigentlicher Zugriff:
				return block.getLists();
			}
			@Override
			protected void onPostExecute(Collection<ShoppingList> result) {
		        for (ShoppingList list : result) {
					Log.d("OutOfAPPles", list.getName());
		        	Toast.makeText(context, list.getName(), Toast.LENGTH_SHORT).show();
		        }
			}
		};
        task.execute();*/
    }

   // @Override
   // public boolean onCreateOptionsMenu(Menu menu) {
   //     getMenuInflater().inflate(R.menu.main_utopia, menu);
   //     return true;
   // }

    public void OnButtonClick(View view){
    	startActivity(new Intent(this, logon_screen.class));
    }
    }
